<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Tymon\JWTAuth\Contracts\JWTSubject;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable implements JWTSubject
{
    use Notifiable;
    //用户表
    protected $table = 'user';

    protected $fillable = [
        'head_img',
        'phone',
        'wx_openid',
        'total_train_time',
        'total_integral',
    ];

    /**
     * Get the identifier that will be stored in the subject claim of the JWT.
     *
     * @return mixed
     */
    public function getJWTIdentifier()
    {
        return $this->getKey();
    }

    /**
     * Return a key value array, containing any custom claims to be added to the JWT.
     *
     * @return array
     */
    public function getJWTCustomClaims()
    {
        return [];
    }

    //头像 head_img
    public function getHeadImgAttribute($value){
        return getDomain().'/'.$value;
    }

    public function scopeWhereId($query, $user_id){
        return $query->where('id',$user_id);
    }

    //关联预约
    public function user_subscribe(){
        return $this->hasMany(UserSubscribe::class,'user_id','id');
    }

    //我的训练
    public function user_train(){
        return $this->hasMany(UserTrain::class,'user_id','id');
    }

}
